﻿using System;
using PMS.XCMG.Entity;
using PMS.XCMG.IBusiness;
using PMS.XCMG.Models;
using PMS.XCMG.Util;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PMS.XCMG.Api.Controllers
{
    /// <summary>
    /// CF_Config
    /// </summary>
    public class CF_ConfigController : BaseController
    {
        public ICF_ConfigBusiness Bus { get; set; }
        public CF_ConfigController(ICF_ConfigBusiness bus)
        {
            this.Bus = bus;
        }

        /// <summary>
        /// 获取单个实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        [HttpGet]
        public Task<CF_Config> GetAsync(string id)
        {
            return this.Bus.GetAsync(id, true);
        }

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        [HttpPost]
        public Task<PageResult<CF_Config>> GetPageAsync(PageInput<CF_ConfigQM> query)
        {
            return this.Bus.GetPageResultAsync(query);
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="data">对应数据</param>
        /// <returns></returns>
        [HttpPost]
        [Transaction]
        public Task<int> SaveAsync(CF_Config data)
        {
            this.InitBusEntity(data);
            return this.Bus.AddOrUpdateAsync(data);
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="ids">数据主键</param>
        /// <returns></returns>
        [HttpDelete]
        [Transaction]
        public Task<int> DeleteAsync(List<string> ids)
        {
            return this.Bus.DeleteAsync(ids);
        }

        /// <summary>
        /// 根据编码获取单个实体
        /// </summary>
        /// <param name="whseId">仓库Id</param>
        /// <param name="code">编码</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseCache(VaryByQueryKeys = new string[] { "whseId", "code" }, Duration = 600)]
        public Task<CF_Config> GetByCodeAsync(string whseId, string code)
        {
            return this.Bus.GetByCodeAsync(whseId, code);
        }
    }
}
